import { formatDate } from '@/utils/formatTime'
import { phoneFormat } from '@/utils/formatter'

import { TableColumns } from '@pureadmin/table'
import { DICT_TYPE } from '@/utils/dict'
import DictTag from '@/components/DictTag/src/DictTag.vue'
import { fenToYuan } from '@/utils'

interface TableColumnList extends Array<TableColumns> {}

export function useUser() {
  const columns: TableColumnList = [
    {
      label: '勾选列', // 如果需要表格多选，此处label必须设置
      type: 'selection',
      minWidth: 55,
      fixed: 'left',
      reserveSelection: true // 数据刷新后保留选项
    },
    { prop: 'id', label: 'ID', width: 100, align: 'center' },
    { prop: 'nickname', label: '姓名|昵称', minWidth: 150, align: 'left', slot: 'nickname' },
    { prop: 'sex', label: '性别', minWidth: 80, align: 'center', slot: 'sex' },
    {
      prop: 'mobile',
      label: '手机',
      minWidth: 120,
      align: 'center',
      slot: 'mobile',
      formatter({ mobile }) {
        return phoneFormat(mobile)
      }
    },
    {
      prop: 'nextBirthday',
      label: '生日',
      minWidth: 130,
      align: 'center',
      formatter({ nextBirthday }) {
        return formatDate(nextBirthday, 'MM-DD')
      }
    },
    { prop: 'age', label: '年龄', minWidth: 120, align: 'center' },

    { prop: 'weight', label: '体重', minWidth: 100, align: 'center', slot: 'weight', hide: true },
    { prop: 'levelName', label: '等级', minWidth: 100, align: 'center' },
    {
      prop: 'memberShip',
      label: '付费会员',
      minWidth: 100,
      align: 'center',
      formatter({ memberShip }) {
        return memberShip ? '是' : '否'
      }
    },
    {
      prop: 'brokerageUserName',
      label: '分销用户',
      minWidth: 100,
      align: 'center',
      hide: true,
      disabledCheck: true
    },
    {
      prop: 'totalPrice',
      label: '综合消费',
      minWidth: 100,
      align: 'center',

      formatter({ totalPrice }) {
        return fenToYuan(totalPrice)
      }
    },
    {
      prop: 'balance',
      label: '会员余额',
      minWidth: 100,
      align: 'center',

      formatter({ balance }) {
        return fenToYuan(balance)
      }
    },
    {
      prop: 'ppcBalance',
      label: '卡类余额',
      minWidth: 100,
      align: 'center',

      formatter({ ppcBalance }) {
        return fenToYuan(ppcBalance)
      }
    },
    {
      prop: 'arrearsPrice',
      label: '欠款金额',
      minWidth: 100,
      align: 'center',

      formatter({ arrearsPrice }) {
        return fenToYuan(arrearsPrice)
      }
    },
    {
      prop: 'debtsPrice',
      label: '负债金额',
      minWidth: 100,
      align: 'center',

      formatter({ debtsPrice }) {
        return fenToYuan(debtsPrice)
      }
    },
    {
      prop: 'serviceNum',
      label: '累计服务',
      minWidth: 100,

      align: 'center'
    },
    {
      prop: 'activeMonthArg',
      label: '月均到店',
      minWidth: 100,

      align: 'center'
    },
    { prop: 'experience', label: '经验值', minWidth: 100, align: 'center' },

    { prop: 'point', label: '积分', minWidth: 100, align: 'center' },
    { prop: 'spreadName', label: '推荐人', minWidth: 100, align: 'center' },
    {
      prop: 'status',
      label: '状态',
      minWidth: 100,
      align: 'center',
      cellRenderer: ({ row }) => <DictTag type={DICT_TYPE.METON_MEMBER_STATUS} value={row.status} />
    },
    {
      prop: 'activeDays',
      label: '距今到店',
      minWidth: 180,
      align: 'center',
      cellRenderer: ({ row }) => <div> {row.activeDays} 天</div>
    },
    {
      prop: 'loginDate',
      label: '上次登录',
      minWidth: 180,
      align: 'center',
      formatter({ loginDate }) {
        return formatDate(loginDate)
      }
    },
    {
      prop: 'createTime',
      label: '注册时间',
      minWidth: 180,
      align: 'center',
      formatter({ createTime }) {
        return formatDate(createTime)
      }
    },
    { prop: 'employee', label: '归属员工', minWidth: 100, fixed: 'right', align: 'center' },
    { prop: 'tenantName', label: '归属门店', minWidth: 100, fixed: 'right', align: 'center' },
    {
      label: '操作',
      fixed: 'right',
      minWidth: 100,
      align: 'center',
      slot: 'operation'
    }
  ]

  return {
    columns
  }
}
